$(function(){
	var url = common.url();
	
	
	//关于点击后的连接问题，以及内容
	var arr = common.search();
	var newsarr = common.baseval('project');
	var showlist = 'gczsp';
	var arr2 = [];
	var arrid = 1;
	var maparr = [];
	if(arr.valid){
		showlist = arr.valid;
	}
	if(arr.proj && arr.proj <= newsarr.length){
		arrid = arr.proj;
	};
	if(arr.valid == 'bxjz'){
		$('.search-box').css({'display':'none'});
	};
	if(newsarr[arrid-1].child.length>0){
		arr2 = newsarr[arrid-1].child
	}
	
	if(arr.pid == 1){
		mapfn(function(){
			map('main1','rgba(0,0,0,0.2)','#231816','#00adea','#ddd','#fa4f04','#00adea','{b}',fnmain1,maparr)
		})
	}else if(arr.pid == 3){
		mapfn(function(){
			map('main2','rgba(0,0,0,0.2)','#231816','#00adea','#ddd','#fa4f04','#00adea','{b}',fnmain2,maparr)
		})
	}else{
		mrsch(1);
	}
	// 百校进展
	
	$('.proj-header ul li').bind('click',function(){
		$(this).addClass('hov8').siblings().removeClass('hov8');
		var aind = $(this).attr('atid');
		mrsch(aind);
	})
	$('.proj2-box .'+ showlist).css({'display':'block'});
	$('.header-list li:last a').html(arr2[arr.pid-1]);
	$('.contll-nav ol li').eq(arr.pid-1).addClass('hov7').siblings().removeClass('hov7');
	// 渲染地图
	function mapfn(fn){
		var jk = common.Interface('proj3')[0];
		$.ajax({
			url : jk,
			type: "POST",
			error: function(request) {
				console.log(request)
			},
			dataType:"json",
			success: function(data) {
				if(!data.ret) return
				var data = data.data;
				if(data.length>0){
					for(var i=0;i<data.length;i++){
						var objarr ={
								name: data[i].name,value: 0,val: data[i].id,
			                    itemStyle: {
			                        normal: {
			                        	color: data[i].color,
			                            label: {
			                                textStyle: {color: '#000'}
			                            }
			                        },
			                        emphasis: { // 也是选中样式
			                            color: 'rgba(0,0,0,0.3)',
			                            label: {
			                                textStyle: {color: '#fa4f04'}
			                            }
			                        }
			                    }
							}
						maparr.push(objarr)
					}
					if(fn){
						fn();
					}
				}else{}
			}
		})
	}
	// 百校进展
	function mrsch(aind){
		var jk = common.Interface('proj3')[1][aind-1];
		$.ajax({
			url : jk,
			type: "POST",
			error: function(request) {
				console.log(request)
			},
			dataType:"json",
			success: function(data) {
				if(!data.ret) return
				$('.proj-val img').attr({'src':data.data});
			}
		})
	}
	// 工程总沙盘
	function fnmain1(param){
		var data = param.data;
		
		$('.main-address').html(data.name);
		var jk = common.Interface('proj3')[3][0]+data.val;
		$.ajax({
			url : jk,
			type: "POST",
			error: function(request) {
				console.log(request)
			},
			dataType:"json",
			success: function(data) {
				if(!data.ret) return
				var data = data.data;
				if(data.length>0){
					var html = '';
					for(var i=0;i<data.length;i++){
						html += '<li><a href="/school.htm?schid='+ data[i].id +'">'+ (i-1+2) +'.&nbsp;'+ data[i].name +'</a></li>';
					}
					$('.main1-val').html(html);
					$('.main1-box').css({'display':'block'});
			        $('.main-mbg').css({'display':'block'});
					$('.main1-box').stop().animate({'opacity':1},200,'linear');
					$('.main-mbg').stop().animate({'opacity':1},200,'linear');
				}else{alert('您选取的省份学校资料正在准备中...')}
			}
		})
        $('.main-box .main-close').bind('click',function(){
        	
        	$('.main1-box').stop().animate({'opacity':0},200,'linear');
        	$('.main-mbg').stop().animate({'opacity':0},200,'linear',function(){
        		$('.main1-box').css({'display':'none'});
        		$('.main-mbg').css({'display':'none'});
        	});
        })
	}
	// 各省进展
 	function fnmain2(param){
		var data = param.data;
		
		$('.main-address').html(data.name);
		var jk = common.Interface('proj3')[3][1]+data.val;
		$.ajax({
			url : jk,
			type: "POST",
			error: function(request) {
				console.log(request)
			},
			dataType:"json",
			success: function(data) {
				if(!data.ret) return
				var data = data.data;
				if(data){
					$('.main2-val img').attr({'src':data.picture})
					$('.main2-box').css({'display':'block'});
			        $('.main-mbg').css({'display':'block'});
			        $('.main2-box').stop().animate({'opacity':1},200,'linear');
					$('.main-mbg').stop().animate({'opacity':1},200,'linear');
				}else{alert('您选取的省份学校资料正在准备中...')}
			}
		})
        $('.main-box .main-close').bind('click',function(){
        	
        	$('.main2-box').stop().animate({'opacity':0},200,'linear');
        	$('.main-mbg').stop().animate({'opacity':0},200,'linear',function(){
        		$('.main2-box').css({'display':'none'});
        		$('.main-mbg').css({'display':'none'});
        	});
        })
	}
 	// obj 加载对象
 	// bgcolor 默认背景颜色
 	// fontcolor 默认字体颜色
 	// bordercolor 默认边框颜色
 	// bgcolor1 默认选中后的背景颜色
 	// fontcolor1 默认选中后的字体颜色
 	// bordercolor1 默认选中后的边框颜色
 	// show 鼠标划入展示的样式
 	// fn 点击个省份执行的fn操作
	function map(obj,bgcolor,fontcolor,bordercolor,bgcolor1,fontcolor1,bordercolor1,show,fn,val){
		require.config({
	        paths: {
	            echarts: 'http://echarts.baidu.com/build/dist'
	        }
	    })
	    require(['echarts', 'echarts/chart/map'], function(ch) {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = ch.init(document.getElementById(obj));
	        option = {
	            tooltip: {
	                trigger: 'item',
					formatter:show
	            },
	            series: [{
	                name: '中国',
	                type: 'map',
	                mapType: 'china', //可以是world,省份中文名
	                selectedMode: 'single', //multiple多选
	                mapLocation: {
	                    x: "10%",
	                    y: "center"
	                },
	                itemStyle: {
	                    normal: {
	                        label: {
	                            show: true,
	                            textStyle: {
	                                color: fontcolor     //字体的颜色
	                            }
	                        },
	                        areaStyle: {
	                            color: bgcolor //背景颜色 
	                        },    
	                        borderColor: bordercolor, //区块的边框颜色
	                    },
	                    emphasis: { //鼠标hover样式
	                        label: {
	                            show: true,
	                            textStyle: {
	                                color: fontcolor1
	                            }
	                        },
	                        areaStyle: {
	                            color: bgcolor1   // 选中之后的背景颜色
	                        },
	                        borderColor: bordercolor1, //区块的边框颜色
	                    }
	                },
	                data: val
	            }]
	        };
	        myChart.on('click', function(param) {
	           fn(param);
	        // 为echarts对象加载数据
	        });
	       myChart.setOption(option);
	    });
	}
})